package com.boatAnchorAssistant.service.controller.web;

import com.boatAnchorAssistant.pojo.param.alarm.*;
import com.boatAnchorAssistant.pojo.vo.alarm.*;
import com.boatAnchorAssistant.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.List;

/**
 * web/报警列表
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/alarm/web")
public class AlarmWebController {

    private final AlarmService service;

    public AlarmWebController(AlarmService service) {
        this.service = service;
    }


    /**
     * 创建报警列表
     *
     * @param param
     * @return
     */
    @PostMapping("/createAlarm")
    public ApiResult createAlarm(@RequestBody @Valid CreateAlarmParam param) {
        service.createAlarm(param);
        return ApiResult.ok();
    }


    /**
     * 修改报警列表
     *
     * @param param
     */
    @PutMapping("/editAlarm")
    public ApiResult editAlarm(@RequestBody @Valid EditAlarmParam param) {
        service.editAlarm(param);
        return ApiResult.ok();
    }

    /**
     * 移除报警列表
     *
     * @param id
     */
    @DeleteMapping("/removeAlarm")
    public ApiResult removeAlarm(@RequestParam("id") Long id) {
        service.removeAlarm(id);
        return ApiResult.ok();
    }

    /**
     * 启动/禁用报警列表
     *
     * @param id
     */
    @GetMapping("/enabledAlarm")
    public ApiResult enabledAlarm(@RequestParam("id") Long id) {
        service.enabledAlarm(id);
        return ApiResult.ok();
    }

    /**
     * 获取报警列表详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getAlarm")
    public ApiResult<GetAlarmVo> getAlarm(@RequestParam("id") Long id) {
        GetAlarmVo vo = service.getAlarm(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取报警列表列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getAlarmList")
    public ApiResult<PageResult<GetAlarmListVo>> getAlarmList(@RequestBody GetAlarmListParam param) {
        PageResult<GetAlarmListVo> result = service.getAlarmList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取报警列表下拉列表
     *
     * @return
     */
    @PostMapping("/getAlarmDownList")
    public ApiResult<List<GetAlarmDownListVo>> getAlarmDownList(@RequestBody(required = false) @Valid GetAlarmDownListParam param) {
        List<GetAlarmDownListVo> list = service.getAlarmDownList(param);
        return ApiResult.ok(list);
    }


}

